<?php include 'head.php';

$row = $DB->get_row("SELECT answer FROM `answer` WHERE `id` = ".intval($_GET['id']));
$info = json_decode($row['answer'], true);
$asks = $DB->getAll("SELECT * FROM `question`");
# 把所有项的键值改成id，方便比对
foreach ($asks as $ask) {
    $question[$ask['id']] = $ask;
}
unset($asks);
// 节省内存啦

foreach ($info as $key => $value) {
    if($key == 'time') continue;
    $echo[$key] = array_merge($question[$key], ['ans'=>$value]);
}
function option2a($option)
{
    switch ($option) {
        case 'options1':
            return 'A';
            break;

        case 'options2':
            return 'B';
            break;

        case 'options3':
            return 'C';
            break;

        case 'options4':
            return 'D';
            break;

        default:
            return false;
            break;
    }
}
?>
    <title>查看详情</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/component/pear/css/pear.css" />
</head>

<body class="pear-container">
    <div class="layui-card">
        <div class="layui-card-header">查看回答详情</div>
        <div class="layui-card-body">
            <table class="layui-table">
                <thead>
                    <tr>
                        <th>题号</th>
                        <th>回答/答案</th>
                        <th>是否正确</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    foreach ($echo as $v) {
                        $y = $v['ans']==$v['answer'] ? '<b>正确</b>' : '错误';
                        echo ("<tr> <td>{$v['id']}</td> <td>".option2a($v['ans'])."/".option2a($v['answer'])."</td> <td>" . $y . "</td> </tr>");
                    }
                    ?>
                </tbody>
            </table>
        </div>
    </div>
</body>

</html>